package com.shuang.mapper;

import com.shuang.pojo.Clazz;
import com.shuang.pojo.ClazzQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface ClazzMapper {
//    分页查询班级列表
    List<Clazz> page(ClazzQueryParam clazzQueryParam);

    /*新增班级信息*/
    @Insert("insert into clazz (name, room, begin_date, end_date, master_id, subject, create_time, update_time) " +
            "values (#{name}, #{room}, #{beginDate}, #{endDate}, #{masterId}, #{subject}, #{createTime}, #{updateTime})")
    void save(Clazz clazz);

    /*根据id查询班级信息*/
    @Select("select id, name, room, begin_date, end_date, master_id, subject, create_time, update_time" +
            " from clazz where id = #{id}")
    Clazz getInfo(Integer id);

    /*更新班级信息*/
    @Update("update clazz set name = #{name}, room = #{room}, begin_date = #{beginDate}," +
            " end_date = #{endDate}, master_id = #{masterId}, subject = #{subject} where id = #{id}")
    void update(Clazz clazz);

    /*删除班级*/
    @Delete("delete from clazz where id = #{id}")
    void delete(Integer id);

    /*查询所有班级*/
    @Select("select id, name, room, begin_date, end_date, master_id, subject, create_time, update_time from clazz")
    List<Clazz> findAll();

    /*统计班级学员人数*/
    @MapKey("num")
    List<Map<String, Object>> getClazzStudentData();

    /*根据id得到班级学员人数*/
    @Select("select count(*) num from student s left join clazz c on c.id = s.clazz_id where s.clazz_id = #{id}")
    Integer getClazzStudentNum(Integer id);
}
